﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Account_Login : System.Web.UI.Page
{

    public User user;

    protected void Page_Load(object sender, EventArgs e)
    {
        RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        user = new User();
    }

    private bool matchesDatabase(string Username, string Password)
    {
        JsonParser jsonParser = new JsonParser();
        bool success = jsonParser.login(Username, Password);

        return success;
    }

    protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        Authenticated = matchesDatabase(LoginUser.UserName, LoginUser.Password);
        user.password = LoginUser.Password;
        user.username = LoginUser.UserName;
        Session["UserSession"] = user;
        e.Authenticated = Authenticated;
    }

}
